{% extends 'base.html' %}

{%block title %}
    {% if tag %}
    标签页: {{ tag.name }}
    {% elif category %}
    标签页: {{ category.name }}
    {% else %}
    首页
    {% endif %}
{%endblock%}

{%block main %}
    {% for post in post_list %}
    <div class="card post">
        <div class="card-body">
            <h5 class="card-title"> <a href="/post/{{post.id}}.html">{{post.title}}</a> </h5>
            <span class="card-link">作者:<a href="#">{{post.owner.username}}</a></span>
            <span class="card-link">分类: <a href="#">{{post.category.name}}</a> </span>
            <span class="card-link">标签:
                {% for tag in post.tag_set %}
                <a href="#">{{tag.name}}</a>
                {% endfor %}
            </span>
            <p class="card-text">{{post.desc}} <a href="{% url 'post-detail' post.id%}">完整内容查看</a> </p>
        </div>
    </div>
    {% endfor %}

    {% if page_obj %}
    <nav aria-label="Page navigation example">
        <ul class="pagination">
            {% if page_obj.has_previous %}
            <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number}}">上一页</a></li>
            {% endif %}

            <li class="page-item active">
              <a class="page-link" href="#">{{page_obj.number}} <span class="sr-only">(current)</span></a>
            </li>

            {% if page_obj.has_next %}
            <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number}}">下一页</a></li>
            {% endif %}
        </ul>
    </nav>
    {%endif%}
{%endblock%}